#include<iostream>
#include<algorithm>
using namespace std;
struct fj{
	int time;
	int money;
};
bool comp(fj x,fj y){
	return x.money>y.money;
}
int main(){
	int m;
	cin>>m;
	int n;
	cin>>n;
	fj s[n];
	int c[n]={0};
	for(int i=0;i<n;i++){
		cin>>s[i].time;
	}
	for(int i=0;i<n;i++){
		cin>>s[i].money;
	}
	sort(s,s+n,comp);
	int q=0;
	for(int i=0;i<n;i++){
		if(c[s[i].time]==0){
			c[s[i].time]=s[i].money;
		}
		else{
			for(int j=s[i].time-1;j>0;j--){
				if(c[j]==0){
					c[j]=s[i].money;
					q=1;
					break;
				}
			}
			if(q==0){
				m-=s[i].money;
			}
			else{
				q=0;
			}
		}
	}
	cout<<m;
}
